package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcSurgeryEntity;
import com.dhcc.cdc.busi.service.ICdcSurgeryService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 手术
 * 
 * @ClassName: CdcSurgeryController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:06
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcsurgery")
public class CdcSurgeryController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcsurgery/";

	@Autowired
	private ICdcSurgeryService cdcSurgeryService;
	

    /**
     * 跳转到手术列表首页
     */
    @RequestMapping("")
    @Permission("cdcsurgery:list")
    public String index() {
        return PREFIX + "cdcsurgery.html";
    }
	
    /**
     * 跳转到新增手术
     */
    @RequestMapping("/to_add")
    @Permission("cdcsurgery:add")
    public String toAdd() {
        return PREFIX + "cdcsurgery_add.html";
    }
	
	/**
     * 跳转到修改手术
     */
    @RequestMapping("/to_update/{cdcSurgeryId}")
    @Permission("cdcsurgery:update")
    public String toUpdate(@PathVariable Long cdcSurgeryId, Model model) {
        CdcSurgeryEntity cdcSurgery = this.cdcSurgeryService.selectById(cdcSurgeryId);
        model.addAttribute("cdcSurgery",cdcSurgery);
        return PREFIX + "cdcsurgery_edit.html";
    }

    /**
     * 获取手术列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcsurgery:list")
    public Object list(@RequestParam Map<String, Object> params) {
        List<CdcSurgeryEntity> result = null;
        Page<CdcSurgeryEntity> page = new PageFactory<CdcSurgeryEntity>().defaultPage();
        if((CommonUtil.isNotEmpty(params.get("NotQuery")))&&(params.get("NotQuery").toString().equals("true"))){
            result = new ArrayList<CdcSurgeryEntity>();
        }else{
            result = this.cdcSurgeryService.page(page,params);
        }
        page.setRecords((List<CdcSurgeryEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增手术
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcsurgery:add")
    @BussinessLog(value = "新增手术")
    public Object add(CdcSurgeryEntity cdcSurgery) {
        if (CommonUtil.isOneEmpty(cdcSurgery)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcSurgery.insert();
        return R.ok();
    }

    /**
     * 删除手术
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcsurgery:delete")
    @BussinessLog(value = "删除手术")
    public Object delete(@RequestParam Long cdcSurgeryId) {
	
        this.cdcSurgeryService.deleteById(cdcSurgeryId);

        return R.ok();
    }

    /**
     * 修改手术
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcsurgery:update")
    @BussinessLog(value = "修改手术")
    public Object update(CdcSurgeryEntity cdcSurgery) {
        if (CommonUtil.isOneEmpty(cdcSurgery)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcSurgeryEntity old = this.cdcSurgeryService.selectById(cdcSurgery.getId());

        old.setEpisodeId(cdcSurgery.getEpisodeId());
        old.setDescription(cdcSurgery.getDescription());
        old.setCode(cdcSurgery.getCode());
        old.setBusSurgTypeId(cdcSurgery.getBusSurgTypeId());
        old.setBusSurgStatusId(cdcSurgery.getBusSurgStatusId());
        old.setStartDate(cdcSurgery.getStartDate());
        old.setEndDate(cdcSurgery.getEndDate());
        old.setSurgLocId(cdcSurgery.getSurgLocId());
        old.setSurgDocId(cdcSurgery.getSurgDocId());
        old.setAssi1st(cdcSurgery.getAssi1st());
        old.setAssi2nd(cdcSurgery.getAssi2nd());
        old.setBusSurgInciId(cdcSurgery.getBusSurgInciId());
        old.setBusSurgHealId(cdcSurgery.getBusSurgHealId());
        old.setBusSurgAnesId(cdcSurgery.getBusSurgAnesId());
        old.setAnesDoc(cdcSurgery.getAnesDoc());
        old.setAsaScore(cdcSurgery.getAsaScore());
        old.setNnisGrade(cdcSurgery.getNnisGrade());
        old.setWbcCount(cdcSurgery.getWbcCount());
        old.setInciCount(cdcSurgery.getInciCount());
        old.setIsEndoscope(cdcSurgery.getIsEndoscope());
        old.setIsImplants(cdcSurgery.getIsImplants());
        old.setBloodLose(cdcSurgery.getBloodLose());
        old.setBloodGet(cdcSurgery.getBloodGet());
        old.setComplication(cdcSurgery.getComplication());
        old.setDataId(cdcSurgery.getDataId());
        old.setIsActive(cdcSurgery.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
